package com.training.admin.handler.api.impl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.demo2do.core.entity.exception.BusinessException;
import com.demo2do.core.entity.result.HttpResult;
import com.demo2do.core.http.annotation.Rao;
import com.training.admin.handler.api.TraineeApiHandler;
import com.training.admin.rao.TraineeRao;

/**
 * @author xiaoHU
 *
 */
@Component("traineeApiHandler")
public class TraineeApiHandlerImpl implements TraineeApiHandler{

    @Rao
    private TraineeRao traineeRao;
    
    @Value("#{config['api.host']}")
    private String host;
    
    /*
     * (non-Javadoc)
     * @see com.training.admin.handler.api.TraineeApiHandler#getTrainees()
     */
    public HttpResult getTrainees() {
        String url = host + "/idm-users";
        HttpResult httpResult = traineeRao.list(url);
        if(!httpResult.isValid()) {
            throw BusinessException.newInstance(httpResult.getCode(), httpResult.getMessage());
        }
        return httpResult;
    }

}
